<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Statistic Monitor</title>
    <link rel="stylesheet" href="/stylesheets/jquery-ui.css">
    <script src="/javascripts/jquery.min.js"></script>
    <script src="/javascripts/jquery-ui.js"></script>
    <script src = "/javascripts/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="/javascripts/jquery.tablesorter.min.js"></script>
    <style type = "text/css">
        @import "/stylesheets/jquery.dataTables.css";
        @import "/stylesheets/jquery.dataTables_themeroller.css";
    </style>
    <link rel="stylesheet" href="/stylesheets/tablesorter.css">
    <script>
        var table = null;

        function requireData(url, data, success) {
            var date = $('#dateField').val();
            var domain = $('#domainField').val();
            data = {
                date  : date,
                domain: domain
            };
            $.getJSON(url, data, function(json) {
                success(json);
            });
        };

        $(document).ready(function() {
            $("#dateField" ).datepicker({
                dateFormat: 'yymmdd'
            });
            $("#dateField").datepicker("setDate", '<%=date%>');
        });

        function search() {
            var date = $('#dateField').val();
            alert(date);
        }
    </script>
</head>
<body>
    <h1>Crawling Daily Statistics <div align='right'> <a href="../">Home</a></div></h1>
    <form action="/monitor/daily" method="get">
    Date: <input type="text"  name="date" id="dateField" style="width: 150px"/>
    <input type="submit" id="search" value="search"/>
    </form>
    <div class = 'wrapper' style="border: 20 20 20 20">
    <table border="1" width="100%"  id="myTable" class="tablesorter">
        <thead>
        <tr bgcolor="#f5f5dc">
            <th>domain</th>
            <th>crawl</th>
            <th>retry</th>
            <th>fail</th>
            <th>lack</th>
            <th>save</th>
            <th>finish</th>
            <th>CONCLUSION</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th>Daily Total</th>
            <th><%=total['crawl']||'0'%></th>
            <th><%=total['retry']||'0'%></th>
            <th><%=total['fail']||'0'%></th>
            <th><%=total['lack']||'0'%></th>
            <th><%=total['save']||'0'%></th>
            <th><%=total['finish']||'0'%></th>
            <th>-</th>
        </tr>


        <% for(var head in result){
            var ir = false;
            var ccu = '';
            if(result[head]['retry']/result[head]['crawl']*1.0>0.31) {ir = true; ccu+='retry/crawl='+(result[head]['retry']/result[head]['crawl']*1.0)+'<br/>';}
            if(result[head]['fail']/result[head]['crawl']*1.0>0.11) {ir = true;ccu+='fail/crawl='+(result[head]['fail']/result[head]['crawl']*1.0)+'<br/>';}
            if(result[head]['lack']/result[head]['crawl']*1.0>0.051) {ir = true;ccu+='lack/crawl='+(result[head]['lack']/result[head]['crawl']*1.0)+'<br/>';}
            if(result[head]['finish']/(result[head]['crawl']-result[head]['retry'])*1.0<0.5) {ir = true;ccu+='finish/(crawl-retry)='+(result[head]['finish']/(result[head]['crawl']-result[head]['retry'])*1.0)+'<br/>';}
            if(result[head]['lack']/result[head]['save']*1.0>0.51) {ir = true;ccu+='lack/save='+(result[head]['lack']/result[head]['save']*1.0)+'<br/>';}
        %>
        <tr<%if(ir){%> bgcolor="#ffc0cb" <%}else{%> bgcolor="#ffffff" <%}%>>
                <td><a href="/monitor/chart?domain=<%=head%>&days=15" target="_blank"><%=head%></a></td>
                <td><%=result[head]['crawl']||'0'%></td>
                <td><%=result[head]['retry']||'0'%></td>
                <td><%=result[head]['fail']||'0'%></td>
                <td><%=result[head]['lack']||'0'%></td>
                <td><%=result[head]['save']||'0'%></td>
                <td><%=result[head]['finish']||'0'%></td>
                <td><%- ccu%></td>
        </tr>
        <% } %>
        </tbody>
    </table></div>
<script>
    $(function()
            {
                $("#myTable").tablesorter( {sortList: [[1,1], [2,1], [3,0], [4,0], [5,1], [6,1]]} );
            }
    );
</script>
</body>
</html>